package com.elsa.server.system.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;

import com.elsa.common.handler.ElsaAccessDeniedHandler;
import com.elsa.common.handler.ElsaAuthExceptionEntryPoint;
/**
 * @projectName：elsa-server-system
 * @typeName：ElsaServerSystemResourceServerConfigure
 * @author：cos
 * @date：2021年5月10日
 * @version
 * @desc：系统模块Web安全配置
 */
@Configuration
@EnableResourceServer
public class ElsaServerSystemResourceServerConfigure extends ResourceServerConfigurerAdapter {
    @Autowired
    private ElsaAccessDeniedHandler accessDeniedHandler;
    @Autowired
    private ElsaAuthExceptionEntryPoint exceptionEntryPoint;
    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.csrf().disable()
                .requestMatchers().antMatchers("/**")
            .and()
                .authorizeRequests()
                .antMatchers("/**").authenticated();
    }
    
    
    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources.authenticationEntryPoint(exceptionEntryPoint)
                .accessDeniedHandler(accessDeniedHandler);
    }
}
